package api.homework.two.one;

import java.util.Random;

/**
 * @author lwj
 * @date 2025-03-11
 * @vesion 1.0.0
 */
public class GatherThread extends Thread{
    @Override
    public void run() {
        // 总数
        int sum = 0;

        // 采集方法
        for(;;){
            sum += new Random().nextInt(1000);
            boolean flag = Thread.currentThread().isInterrupted();

            if(flag){
                System.out.println("采集结束");
                break;
            }

            try {
                Thread.sleep(2000);

                System.out.println("当前采集的结果为："+sum);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }
    }
}
